package com.bjc.base.web;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.bjc.base.service.IBookClassificationService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.bjc.base.bean.request.BookClassificationReqVO;
import com.bjc.base.bean.response.BookClassificationVO;

/**
 * <p>
 * 绘本分类 前端控制器
 * </p>
 *
 * @author 许自辉
 * @since 2018-06-10
 */
@RestController
@RequestMapping("api/book")
@Api(value = "bookClassification-api", tags = { "绘本分类相关接口" })
public class BookClassificationController {

    @Autowired
    private IBookClassificationService bookClassificationService;

	@ApiOperation("分页查询绘本分类")
	@GetMapping("bookClassification/findPage")
	public ResultVO getBookClassificationPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			BookClassificationReqVO bookClassificationReqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<BookClassificationVO> bookClassificationVOs = bookClassificationService.getList(bookClassificationReqVO);
		return ResultGenerator.getSuccess(new PageInfo<BookClassificationVO>(bookClassificationVOs));
	}
	
	@ApiOperation("分页查询绘本分类")
	@GetMapping("bookClassification/find")
	public ResultVO getBookClassificatione(BookClassificationReqVO bookClassificationReqVO) {
		BookClassificationVO bookClassificationVO = bookClassificationService.get(bookClassificationReqVO);
		return ResultGenerator.getSuccess(bookClassificationVO);
	}

	@ApiOperation("添加绘本分类")
	@PostMapping("bookClassification/create")
	public ResultVO createBookClassification(@RequestBody BookClassificationReqVO bookClassificationReqVOs) {
		int count = bookClassificationService.insert(bookClassificationReqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新绘本分类")
	@PutMapping("bookClassification/update")
	public ResultVO updateBookClassification(@RequestBody BookClassificationReqVO bookClassificationReqVOs) {
		int count = bookClassificationService.update(bookClassificationReqVOs);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("批量删除绘本分类")
	@DeleteMapping("bookClassification/deleteList")
	public ResultVO deleteBookClassification(@ApiParam(value = "bookClassification id集合") @RequestBody int[] ids) {
		int count = bookClassificationService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}

}
